package com.xiaoba.shoppingcart.test;

import com.alibaba.fastjson2.JSONObject;
import com.alipay.api.*;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.xiaoba.common.security.utils.SecurityUtils;
import com.xiaoba.system.domain.model.LoginUser;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.net.URL;
import java.util.HashMap;

/**
 * @Author：liushize
 * @Package：com.bawei.mall.car.test
 * @Project：mall-cloud_1
 * @name：Opendocs
 * @Date：2024/5/11 10:29
 */
@SpringBootTest
public class Opendocs {

    @Test
    public static void main(String[] args) throws AlipayApiException {

        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi-sandbox.dl.alipaydev.com/gateway.do",
                "9021000137696539",
                "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDIDCPhKJ8MLNRahMGOzgEjzuDHqghVmma0wBLPgTM1JdnntPHBxhs26ImM3EBR2e5ZThUH70eLLJ3wka4k931Xb07RgS/c+pH9Vzi1CB9KWKdU28tWHvsQda/4AS95gS5c82HTJzZ7tNRQPOGkURKpZu77Ns1k0jNUYdp7CLpJjj5J/EojXm/aVLK7bfDvdTwmlyBLKZ3gyvZXDXXE+1Yp8NBlG0/vse/78HnN2P9THL+J63nZDNgVdyUO3sOnxzuvUgCablbyIk8iAeVUNmsa0Kd0P75no2+W0v+UgL+JdOYfaGUcv0cDhPVj+xbGufr4HE4Xm2WqMQTGK0E346AXAgMBAAECggEBAK+UQDWSAq6b9jIQjRY65zM3k4CLU09W+kgwwRHRc1F1jGDbJsmNiDtUM84nTmjI33MQnlLdiCy2F1Wbd35InoGMV2B4g7rvTg1ObZ4up9AIKa3IUBqhjHhw4ubIm5OId1nr3/OFWkOPfj2CggVHhxqaFqz096dC+vxX+nu8OEzvd5NAH4OfuDUAES5oIOvuZeUyHP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CAQ8AMIIBCgKCAQEAsIUjZHJSaZ8kRHD4wMn0qA7vkAhI8+5PPU/hS5vrtePYIAlPK9uPTdkC/+84QAnRSuSCnBfEWle9eA366kUTTUDKXnISbCuBX0xRMr8o/j7oF1ExljUM6jq0nw17hT7CAL6KnLNXhFFmgJ89uqQ3Unmdeu+pegWh99ez5FrpyHsENnpjhtX+DRU+K22K1SJKkkLsmEBbv2gJRgjkA0qRTI1j8YC2IODNELnb1aswKQmWKFFCqbCgMdQFAaYcG/dbQWbu3TXUHrSbUPoWAc2yNruYOPWf0mOENHWiYDjyZYvEklOWmkk4VwKRVM+Y9rBfmxNhw2Suob5Yfxorc+/2ZwIDAQAB",
                "RSA2");
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        //异步接收地址，仅支持http/https，公网可访问
        request.setNotifyUrl("");
        //同步跳转地址，仅支持http/https
        request.setReturnUrl("");
        /******必传参数******/
        JSONObject bizContent = new JSONObject();
        //商户订单号，商家自定义，保持唯一性
        bizContent.put("out_trade_no", "20210817010101026");
        //支付金额，最小值0.01元
        bizContent.put("total_amount", 1000.0);
        //订单标题，不可使用特殊符号
        bizContent.put("subject", "测试商品");
        //电脑网站支付场景固定传值FAST_INSTANT_TRADE_PAY
        bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");

        request.setBizContent(bizContent.toString());
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request, "POST");
        // 如果需要返回GET请求，请使用
        // AlipayTradePagePayResponse response = alipayClient.pageExecute(request,"GET");
        String pageRedirectionData = response.getBody();
        System.out.println(pageRedirectionData);

        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }

    }
}
